package com.example.exception;

import org.springframework.http.HttpStatus;

import java.io.Serializable;
//实现序列化是在分布式框架中能够传输
public class ServiceException extends  RuntimeException implements Serializable{
     enum MrrorType{
        BAD_REQUEST(HttpStatus.BAD_REQUEST), FORBIDDEN(HttpStatus.FORBIDDEN), NOT_FOUND(HttpStatus.NOT_FOUND);
        private final HttpStatus status;
        MrrorType(HttpStatus status) {
            this.status=status;
        }

        public HttpStatus getStatus() {
            return status;
        }
    }
    private String code;
    private String message;
    private MrrorType mrrorType;

     ServiceException() {
    }

     ServiceException(String code, String message, MrrorType mrrorType) {
        this.code = code;
        this.message = message;
        this.mrrorType = (mrrorType == null? MrrorType.BAD_REQUEST:mrrorType);
    }

    public String getCode() {
        return code;
    }
    public String getMessage() {
        return message;
    }
    public MrrorType getMrrorType() {
        return mrrorType;
    }
    public static ServiceException createException(String code){
        return new ServiceException(code,null,null);
    }
    public static ServiceException createException(String code,String message){
        return new ServiceException(code,message,null);
    }
    public static ServiceException createException(String code,String message,MrrorType type){
        return new ServiceException(code,message,type);
    }


}
